package com.fuqi.android.zhongcai.business.shuig.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.TextView;

import com.fuqi.android.zhongcai.R;
import com.fuqi.android.zhongcai.base.request.result.bean.VisitBean;
import com.fuqi.android.zhongcai.business.shuig.request.result.GetCheckInfoResult.CheckForList;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ChouCha2Adapter extends BaseAdapter {
	private List<CheckForList> listBean = new ArrayList<>();
	private Context context;
	private Map<String,View> mgvs;

	public ChouCha2Adapter(Context context, List<CheckForList> listBean) {
		this.context = context;
		this.listBean = listBean;
		mgvs = new HashMap<String,View>();
	}
	public void setDate(List<CheckForList> listBean) {
		this.listBean = listBean;
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return listBean.size();
	}

	@Override
	public CheckForList getItem(int position) {
		return listBean.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.item_choucha, null);
			viewHolder.tvTitle = (TextView) convertView.findViewById(R.id.tv_title);
			viewHolder.gvItem = (GridView) convertView.findViewById(R.id.gv_item);
			viewHolder.etRemark = (EditText) convertView.findViewById(R.id.et_remark);

			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		final List<VisitBean> datass = makeAnswers(getItem(position));
		AnswerAdapter mTypeAdapter = new AnswerAdapter(context,datass);
		viewHolder.gvItem.setAdapter(mTypeAdapter);
		for (int i = 0;i < datass.size();i++){
			if(datass.get(i).getBaseCode().equals(getItem(position).getResult())) {
				viewHolder.gvItem.setItemChecked(i, true);
			}
		}
		viewHolder.etRemark.setText(getItem(position).getREMARK());
		viewHolder.tvTitle.setText(getItem(position).getQUESTION_NAME());
		viewHolder.gvItem.setEnabled(false);
		return convertView;
	}

	List<VisitBean> makeAnswers(CheckForList check){
		List<VisitBean> datas = new ArrayList<>();
		VisitBean bean1 = new VisitBean();;
		VisitBean bean2 = new VisitBean();
		bean1.setName("是");
		bean2.setName("否");
		bean1.setBaseCode("1");
		bean2.setBaseCode("0");

		datas.add(bean1);
		datas.add(bean2);
		return datas;
	}

	private class ViewHolder{
        TextView tvTitle;
        GridView gvItem;
		EditText etRemark;
    }


}
